
var qQuery = new Query({container:$("#listWrap")});
var sSearch = new Search({ container : $("#searchWrap")});
//var sSelected = new Selected({container:$("#seledUl")})
var Main = RichBase.extend({
	statics : {},
	EVENTS : {
		"click" : {
			".topUl" : "onTopUlClick",
			".list_data .yujbtn" : "onSetSelected",
			".pub_history" : "history_list",
			".pub_normal" : "normal_list"
		}
	},
	init : function(opt){
		var that = this;
		this.container = opt.container;
		this.prevBtn = $("#prevPageBtn");
		this.nextBtn = $("#nextPageBtn");
		sSearch.on("search",function(opt){
			that.prevBtn.addClass("disable");
			$("#whichPageNum").text(1)
			qQuery.setCurPage(0);
			qQuery.setData();
			qQuery.query(opt);
		});
		qQuery.on("no_next",function(res){
			that.nextBtn.addClass("disable");
		});
		qQuery.on("has_next",function(res){
			that.nextBtn.removeClass("disable");
		});
		qQuery.on("query_nexta",function(last,total){
			var searchData = sSearch.getData();
			//console.log(searchData.province)
			qQuery.query({
				province : searchData.province,
				city : searchData.city,
				title : searchData.title,
				supplier : searchData.supplier,
				total : total,
				last : last
			})
		});
		qQuery.on("query_nextb",function(last,total){
			var searchData = sSearch.getData();
			//console.log(searchData.province)
			qQuery.query({
				province : searchData.province,
				city : searchData.city,
				title : searchData.title,
				supplier : searchData.supplier,
				total : total,
				status:"2",
				last : last
			})
		});
		qQuery.on("query_ago",function(last){
			var searchData = sSearch.getData();
			qQuery.query({
				city : searchData.city,
				province : searchData.province,
				title : searchData.title,
				supplier : searchData.supplier,
				last : last
			})
		});
		qQuery.query();
	
	},
	history_list : function(that,e){
			var searchData = sSearch.getData();
			$(".pub_top_left").attr("data_li","2");
			qQuery.query({
				title : searchData.title,
				supplier : searchData.supplier,
				status:"2"
			})
		
		
	},
	normal_list : function(that,e){
		var searchData = sSearch.getData();
			$(".pub_top_left").attr("data_li","0");
			qQuery.query({
				title : searchData.title,
				supplier : searchData.supplier,
				status:"0"
			})
		
		
		
	},
	
	onSetSelected : function(that,e){
		var target = $(e.currentTarget);
		var parent = target.parent();
		var yucln = e.target.className;
		var lid_pid = target.attr("data-pid"); 
		var aid = target.attr("data-id"); 
		var active = target.attr("data-active"); 
		//var lid_pid = parent.children("[name=lid_pid]").val();
		//if(target.attr("checked")){
		if(yucln == "yujbtn onyuj"){  // 清
			sData.set(lid_pid,aid,{
				active : 0 
			},function(data){
				//sSelected.render(data);
				console.log(data);
			});
		}else{
			sData.set(lid_pid,aid,{
				active : 1
			},function(data){
				console.log(data);
				//sSelected.render(data);
			})
		}
	},
	onTopUlClick : function(that,e){
		var tarTop = $(e.currentTarget);
		var p = tarTop.parent();
		var botW = tarTop.next();
		if(p.hasClass("selected")){
			botW.slideToggle(function(){
				p.toggleClass("selected");
			});
		}else{
			p.toggleClass("selected");
			botW.slideToggle();
		}
	}
});

$("#mlistUl").on("click",".del",function(e){
	var target = $(e.currentTarget);
	var data_e = target.attr("data_id");
	var data = {
		action : "coupon_ch_state", 
		status : "2",
		id : data_e
	};
	var r=confirm("您确定要将此优惠券下架？")
	  if (r==true)
		{
			PFT.Ajax({
			url : "/call/jh_coupon.php",
			type : "GET",
			dataType : "json",
			data : data
			}
			,function(data){
				var status = data.status;
				if(status=="success"){
					target.parents(".setbg_a").remove();
					PFT_GLOBAL.U.Alert("success",'<p style="width:240px">下架成功</p>');
				}
			})
		}
	  else
		{
		return false;
		}


	
})

new Main({container:$("#dmlistUI")});

